package com.thoughtworks.preuniversityprogram.biblioteca;

import java.util.HashMap;
import java.util.List;

/**
 * Created by padmavb on 6/10/14.
 */
public class ListBooks extends Library {

    public List<Book> listBooks(List<Book> checkOutBooks) {

        Library library=new Library();
        library.createListOfBookObjects();

        List<Book> listOfBookObjects=library.getListOfBookObjects();

        HashMap<Integer,Book> listOfAvailableBooks=convertToHashMap(listOfBookObjects);
        HashMap<Integer,Book> checkOutBooksHashMap=convertToHashMap(checkOutBooks);

        for(Book i:checkOutBooksHashMap.values()){
            if(listOfAvailableBooks.containsKey(checkOutBooks.indexOf(i)))
                listOfAvailableBooks.remove(checkOutBooks.indexOf(i));
        }
        String space= "               ";
        for(int index:listOfAvailableBooks.keySet()){

            Book book=listOfAvailableBooks.get(index);
            System.out.print(book.getTitle()+space+book.getAuthorName()+space+
                book.getPublishedYear()+"\n");


        }
        return listOfBookObjects;
    }

    public HashMap<Integer,Book> convertToHashMap(List<Book> listOfBooks){

        HashMap<Integer,Book> hashMapBooks=new HashMap<Integer, Book>();
        for(int index=0;index<listOfBooks.size();index++){

            hashMapBooks.put(index,listOfBooks.get(index));
        }
        return hashMapBooks;
    }
}
